package com.youlin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youlin.dto.BaseDataResDto;
import com.youlin.dto.Status;
import com.youlin.dto.res.AllTTResDto;
import com.youlin.entities.BygTextTemplate;
import com.youlin.mapper.BygTextTemplateMapper;
import com.youlin.service.BygTextTemplateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class BygTextTemplateServiceImpl extends ServiceImpl<BygTextTemplateMapper, BygTextTemplate> implements BygTextTemplateService {

    @Override
    public BaseDataResDto<List<AllTTResDto>> findAllTxTls() {
        List<BygTextTemplate> textTemplates = list(new QueryWrapper<>());
        if (textTemplates.size() == 0) return new BaseDataResDto<>(Status.SUCCESS);
        Map<String, List<BygTextTemplate>> ttListMap = textTemplates.parallelStream()
                .collect(Collectors.groupingBy(BygTextTemplate::getName));
        List<AllTTResDto> allTTResDtos = ttListMap.keySet().parallelStream().map(k ->
                new AllTTResDto().setName(k).setTts(ttListMap.get(k))).collect(Collectors.toList());
        return new BaseDataResDto<List<AllTTResDto>>(Status.SUCCESS).setData(allTTResDtos);
    }

}
